require('./index.css');
var _account_service = require('service/account-service.js')

var top = {
    // username : "小鲫瓜子",
    init : function(){
        this.bindEvents();
        this.loadAccountInfo();
        return this;
    },
    bindEvents : function(){
        $('#signout_btn').click(
            function(){
                _account_service.logout(
                    function(res){
                        window.location.reload();
                    },
                    function(errorMsg){
                        //暂时什么都不做
                    }
                )
            }
        ),
        $('#toCart').bind('click',
        function () {
            var isLogin = false;
            _account_service.checkLogin(
                function (res) {
                    window.location.href = './cart.html'
                },
                function (err) {
                    alert("请先登录")
                    window.location.href = './user-login.html'
                }
            )
            
        }
    )
    },
    loadAccountInfo : function(){
        // var _this = this;
        _account_service.checkLogin(
            function(res){
                // _this.username = res.username;
                $('#signInSpan').hide();
                $('#signOutSpan').show();
            },
            function(errMsg){
                $('#signInSpan').show();
                $('#signOutSpan').hide();
            }
        );
    },
};


module.exports = top.init();